//秘钥必须为：8/16/32位
import crypto from 'crypto-js'
import { JSEncrypt } from 'jsencrypt'
const encryptStr = (12121.2234).toString(32);
export function encryptCommon(message) {
  return crypto.AES.encrypt(
    message,
    crypto.enc.Utf8.parse(encryptStr.slice(2, 10)),
    {
      mode: crypto.mode.ECB,
      padding: crypto.pad.Pkcs7,
    }
  ).toString();
}
export function decryptCommon(message) {
  return crypto.AES.decrypt(
    message,
    crypto.enc.Utf8.parse(encryptStr.slice(2, 10)),
    {
      mode: crypto.mode.ECB,
      padding: crypto.pad.Pkcs7,
    }
  ).toString(crypto.enc.Utf8);
}

export function encryptMd5(message) {
  return crypto.MD5(message).toString();
}
export function encryptRSA(message, publicKey) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  const encryptedStr = encryptor.encrypt(message);
  console.log(publicKey, "publicKey-------------------------");
  console.log(encryptedStr, "encryptedStr-------------------------");
  return encryptedStr;
}
export function decryptRSA(message, privateKey) {
  const decryptor = new JSEncrypt();
  decryptor.setPrivateKey(privateKey);
  const decryptedStr = decryptor.decrypt(message);
  console.log(privateKey, "privateKey-------------------------");
  console.log(decryptedStr, "decryptedStr-------------------------");
  return decryptedStr;
}
